package managers.conversationManager;

import java.io.IOException;
import java.sql.PreparedStatement;
import java.util.ResourceBundle;

import managers.DBManager;
import managers.messengerManager.MessengerManager;

public class OfflineConversation extends Conversation  {

	public OfflineConversation (int userId) {
		
		this.userId = userId;
		chat = convManager.getChatManager().getChat(userId);
		
		chat.setEnabled(true);
		chat.enableFeatures("fileTransfer", false);
		chat.enableFeatures("trill", false);
		chat.updateStatus("<HTML><b>"+chat.getReceiverName()+ResourceBundle.getBundle("managers.conversationManager.messages").getString("m.2"), null);
	}


	@Override
	public void sendMessage(byte[] message) throws Exception {
		
		PreparedStatement stmt = DBManager.getConnection().prepareStatement("INSERT INTO spotmessenger.pending_messages (senderid, receiverid, body) VALUES (?, ?, ?)");
		stmt.setInt(1, MessengerManager.getSharedInstance().getUserId());
		stmt.setInt(2, userId);
		stmt.setBytes(3, message);
		stmt.executeUpdate();
		
		DBManager.closeResources(stmt, null);
		
	}

	@Override
	public void sendWritingState(int state) throws IOException {
		//do nothing	
	}


	@Override
	public void closeConnection() throws IOException {
		//do nothing
	}

}
